<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑文章</title>
    <link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                  <div class="layui-form-item ">
                  	<div class="layui-col-md6">
					    <label class="layui-form-label">所属栏目</label>
					    <div class="layui-input-inline">
					      <select name="txtChannelno">
									<option value="">{$tree['title']}</option>
									{volist name="tree['children']" id="vo"}
									<option {if condition="$vo['id'] eq $one['channel_id'] OR $parent eq $vo['id']"} selected="selected"{/if} value="{$vo['id']}">&nbsp;&nbsp;{$vo['title']}</option>
										{volist name="vo['children']" id="cvo"}
											<option {if condition="$cvo['id'] eq $one['channel_id'] OR $parent eq $cvo['id']"} selected="selected"{/if} value="{$cvo['id']}">&nbsp;&nbsp;&nbsp;&nbsp;{$cvo['title']}</option>
										{/volist}
									{/volist}
							</select>
					    </div>
				    </div>
				    <div class="layui-col-md6">
					    <label class="layui-form-label">内容类型</label>
					    <div class="layui-input-inline">
					      <select name="sltType" lay-verify="">
									<option value="">请选择模型</option>
									{volist name="type" id="vo"}
									<option {if condition="$vo['type_id'] eq $one['type_id']"} selected="selected"{/if} value="{$vo['type_id']}">{$vo['type_name']}</option>
									{/volist}
							</select>
					    </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				  <div class="layui-col-md12">
				    <label class="layui-form-label">标题</label>
				    <div class="layui-input-inline" style="width:660px;">
				      <input type="text" name="txtTitle" value="{$one['title']}" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				  <div class="layui-col-md12">
				    <label class="layui-form-label">外部链接</label>
				    <div class="layui-input-inline" style="width:660px;">
				      <input type="text" name="txtLinkUrl" value="{$one['link']}" required  lay-verify="required" placeholder="请输入外部链接" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				  <div class="layui-col-md6">
				    <label class="layui-form-label">短标题</label>
				    <div class="layui-input-inline">
				      <input type="text" name="txtShortTitle" value="{$one['short_title']}" required  lay-verify="required" placeholder="请输入代码名称" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				    
				    <div class="layui-col-md6">
				    <label class="layui-form-label">作者</label>
				    <div class="layui-input-inline">
				      <input type="text" name="txtAuthor" value="{$one['author']}" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				   <div class="layui-col-md12">
				   		<label class="layui-form-label">摘要</label>
						<textarea name="txtDescription" placeholder="" class="layui-textarea" style="width:660px;">{$one['description']}</textarea>
					</div>
				  </div>
				  
				  <div class="layui-form-item">
				  	<div class="layui-col-md6">
				    <label class="layui-form-label">来源</label>
				    <div class="layui-input-inline">
				      <input type="text" name="txtOrgin" value="{$one['origin']}" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				    
				    <div class="layui-col-md6">
				    <label class="layui-form-label">来源URL</label>
				    <div class="layui-input-inline">
				      <input type="text" name="txtOrginUrl" value="{$one['origin_url']}" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				  	<div class="layui-col-md6">
				    <label class="layui-form-label">是否推荐</label>
				    <div class="layui-input-inline">
				      <input type="checkbox" name="chkIsRecommend" {if condition="$one['is_recommend'] eq 1"} checked="checked"{/if} value="1" title="是" >
				    </div>
				    </div>
				    
				    <div class="layui-col-md6">
				    <label class="layui-form-label">是否草稿</label>
				    <div class="layui-input-inline">
				      <input type="checkbox" name="chkStatus" {if condition="$one['status'] eq '0' "} checked="checked" {/if} value="1" title="是" >
				    </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				  	<div class="layui-col-md6">
				    <label class="layui-form-label">排序</label>
				    <div class="layui-input-inline">
				      <input type="text" name="txtTopLevel" value="{$one['top_level']}" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				    
				    <div class="layui-col-md6">
				    <label class="layui-form-label">发布时间</label>
				    <div class="layui-input-inline">
				      <input type="text" id="txtReleaseDate" name="txtReleaseDate" value="{$one['release_date']}" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				  	<div class="layui-col-md6">
				    <label class="layui-form-label">标题图片</label>
				    <div class="layui-input-inline">
				      <input type="text" id="txtTitleImgP" name="txtTitleImgP" value="{$one['title_img']}" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				    
				    <div class="layui-col-md6">
				    	<button type="button" class="layui-btn layui-btn-danger" id="titpic"><i class="layui-icon"></i>上传图片</button>
				    	<div class="layui-upload-list">
					    	<img class="layui-upload-img" id="titimg" {if condition="$one['title_img'] neq '' "}src="{$one['title_img']} {/if}" width="150">
					  	</div>
				    </div>
				    
				  </div>
				  
				  <div class="layui-form-item">
				    <div class="layui-col-md6">
				    <label class="layui-form-label">内容图片</label>
				    <div class="layui-input-inline">
				      <input type="text" id="txtContentImgP" name="txtContentImgP" value="{$one['content_img']}" autocomplete="off" class="layui-input">
				    </div>
				    </div>
				    
				    <div class="layui-col-md6">
				    	<button type="button" class="layui-btn layui-btn-danger" id="conpic"><i class="layui-icon"></i>上传图片</button>
				  		<div class="layui-upload-list">
					    	<img class="layui-upload-img" id="conimg" {if condition="$one['content_img'] neq '' "}src="{$one['content_img']} {/if}" width="150">
					  	</div>
				  	</div>
				  </div>
				  
				  <div class="layui-form-item">
				  	<div class="layui-col-md12">
				    <p style="color:#ff6a08;text-align:center;"> * 建议点击编辑器右上角 "全屏" 图标，使用全屏模式编辑</p>
				    </div>
				  	<div class="layui-col-md12">
				    <label class="layui-form-label">文章内容</label>
				    <div class="layui-input-inline" style="width: 660px; height: 400px;">
				    	<script id="editor" name="txtContent"  type="text/plain" style="width: 660px; height: 400px;"></script>
				    </div>
				    </div>

				  </div>
				  
				  <input name="option" type="hidden" value="{$option}"/>
				  <input name="txtContentno" type="hidden" value="{$one['content_id']}"/>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="type-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="__STATIC__/lib/layui/layui.js"></script>
<script src="__PEAR__/component/pear/pear.js"></script>
<script>

var ue = UE.getEditor('editor');
//编辑器加载完毕后执行操作
ue.ready(function() {
	ue.setContent('{$one["txt"]|raw}',false);
});

layui.use(['form','jquery','laydate','upload'],function(){
	
	var laydate = layui.laydate;
	var upload = layui.upload;
    let form = layui.form;
    let $ = layui.jquery;
    
    laydate.render({
        elem: '#txtReleaseDate'
        ,type: 'datetime'
    });
    
	//标题图片上传
	upload.render({
	    elem: '#titpic'
	    ,url: "/{$MODULE_NAME}/portal/content/upload/channelno/{$parent}" //此处配置你自己的上传接口即可
	    ,method: 'post'
	    ,size: 2048 //限制文件大小，单位 KB
	    ,done: function(res){
	     	$("#txtTitleImgP").val(res.data.path);
	     	$("#titimg").attr("src",res.data.path);
	    },error: function(index, upload){ //上传失败
	    	layer.msg('上传失败，请重试');
	    }
	  });
	
	//内容图片上传
	upload.render({
	    elem: '#conpic'
	    ,url: "/{$MODULE_NAME}/portal/content/upload/channelno/{$parent}" //此处配置你自己的上传接口即可
	    ,method: 'post'
	    ,size: 2048 //限制文件大小，单位 KB
	    ,done: function(res){
	    	$("#txtContentImgP").val(res.data.path);
	    	$("#conimg").attr("src",res.data.path);
	    },error: function(index, upload){ //上传失败
	    	layer.msg('上传失败，请重试');
	    }
	  });
    
    var path="/{$MODULE_NAME}/portal/content";
	var _url="/save";
    form.on('submit(type-save)', function(data){
        $.ajax({
            url:path+_url,
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(result){
                if(result.code){
                    layer.msg(result.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("channel-table",{
							where:{'parent':'{$parent}'}
						});
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:1000});
                }
            }
        })
        return false;
    });
})
</script>
<script>
</script>
</body>
</html>